import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { WrestleGroupResult } from "./WrestleGroupResult";
import { ObjCreate } from "../../common/ObjCreate";
import { WrestleGroupDetail } from "./WrestleGroupDetail";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { SWrestleResult } from "../../../../../Message/Public/SWrestleResult";
import { SWrestlePlayerResult } from "../../../../../Message/Public/SWrestlePlayerResult";
import { Cache } from "../../../cache/Cache";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class WrestleResultWindow
    
    export  class WrestleResultWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(377, 305);
            titleHeight = 26;
            title = Language.getString(42242);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._wrestleGroupResultOne = new WrestleGroupResult();
            ObjCreate.setObjAttri(this._wrestleGroupResultOne, 17, 40, -1, -1, this);
            this._wrestleGroupResultTwo = new WrestleGroupResult();
            ObjCreate.setObjAttri(this._wrestleGroupResultTwo, 190, 40, -1, -1, this);
            this._wrestleGroupDetail = new WrestleGroupDetail();
            ObjCreate.setObjAttri(this._wrestleGroupDetail, 377, 0, -1, -1, this);
            var loc1=GlobalClass.getBitmap(ImagesConst.ArenaVS);
            ObjCreate.setObjAttri(loc1, 167, 98, -1, -1, this);
            var loc2=220;
            var loc3=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            this._tfExpReward = ObjCreate.createTextField(Language.getStringByParam(42244, "0"), 22, loc2, 150, 22, this, loc3);
            var loc4=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            this._tfMoneyReward = ObjCreate.createTextField(Language.getStringByParam(42246, "0"), 192, loc2, 150, 22, this, loc4);
            this._btnSaveVideo = ObjCreate.createGButton(Language.getString(42342), 105, loc2 + 25, 70, 26, this, "ButtonRedMini");
            this._btnSaveVideo.addEventListener(flash.events.MouseEvent.CLICK, this.onClickSaveVideo);
            this._btnOK = ObjCreate.createGButton(Language.getString(42343), 200, loc2 + 25, 70, 26, this, "ButtonRedMini");
            this._btnOK.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnOKClick);
            ObjCreate.createFireTip(Language.getString(42344), 70, loc2 + 48, this, true);
            return;
        }

        /* internal  */onClickSaveVideo(arg1: Object /* flash.events.MouseEvent */): void
        {
            Alert.show(Language.getString(42345), null, Alert.OK | Alert.CANCEL, null, this.onCloseAlert);
            return;
        }

        /* internal  */onCloseAlert(arg1: int): void
        {
            if (arg1 == Alert.OK && this._result) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleSaveVideo, this._result.fightRecordId));
            }
            return;
        }

        /* internal  */onBtnOKClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            if (GameMapUtil.curMapState.isWrestle) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleExitNow));
            }
            return;
        }

        public updateResult(arg1: SWrestleResult): void
        {
            this._result = arg1;
            this._wrestleGroupDetail.visible = false;
            if (arg1.groupOne.length > 1) 
            {
                this._wrestleGroupDetail.updateData(arg1.groupOne);
            }
            if (arg1.groupTwo.length > 1) 
            {
                this._wrestleGroupDetail.updateData(arg1.groupTwo);
            }
            this._wrestleGroupResultOne.updateResult(arg1.groupOne, arg1.groupOneResult, false, 1);
            this._wrestleGroupResultTwo.updateResult(arg1.groupTwo, arg1.groupTwoResult, false, 1);
            this._tfExpReward.text = Language.getStringByParam(42244, arg1.expReward.toString());
            this._tfMoneyReward.text = Language.getStringByParam(42246, arg1.moneyReward.toString());
            if (arg1.isBattler) 
            {
                this._tfExpReward.visible = true;
                this._tfMoneyReward.visible = true;
                this._btnSaveVideo.visible = true;
                this._btnSaveVideo.x = 105;
                this._btnOK.x = 200;
            }
            else 
            {
                this._tfExpReward.visible = false;
                this._tfMoneyReward.visible = false;
                this._btnSaveVideo.visible = false;
                this._btnOK.x = 153;
            }
            return;
        }

        /* internal  */getPlayerResult(arg1: SWrestleResult): SWrestlePlayerResult
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < arg1.groupOne.length) 
            {
                loc1 = arg1.groupOne[loc2] as SWrestlePlayerResult;
                if (loc1.miniPlayer.entityId.id == Cache.instance.role.entityInfo.entityId.id) 
                {
                    return loc1;
                }
                ++loc2;
            }
            return null;
        }

        /* internal  */layOut(): void
        {
            return;
        }

        /* internal */ /* var */_wrestleGroupResultOne: WrestleGroupResult;

        /* internal */ /* var */_wrestleGroupResultTwo: WrestleGroupResult;

        /* internal */ /* var */_wrestleGroupDetail: WrestleGroupDetail;

        /* internal */ /* var */_tfExpReward: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMoneyReward: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnOK: GButton;

        /* internal */ /* var */_btnSaveVideo: GButton;

        /* internal */ /* var */_result: SWrestleResult;
    }
